<?php

$db = new swoole_mysql();
$config = [
    "host" => "localhost",
    "user" => "root",
    "password" => "root",
    "database" => "mysql",
    "charset" => "utf8",
];
$db->connect($config, function($db, $r) {
    if ($r === false) {
        var_dump($db->connect_errno, $db->connect_error);
        die("失败");
    }
    $sql = "show tables";
    $db->query($sql, function(swoole_mysql $db, $r) {
        var_dump($r);
        if ($r === false) {
            var_dump($db->error);
            die("查询失败");
        } elseif ($r === true) {
            var_dump($db->affected_rows, $db->insert_id);
        }
        $db->close();
    });
});